package com.dykj.dati.utils;

import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dykj.dati.model.t.TJiaojuan;
import com.dykj.dati.model.t.TXiangQing;
import com.dykj.dati.model.t.TiJiaoJuan;
import com.dykj.dati.model.user.HUser;
import com.dykj.dati.service.t.ITJiaojuanService;
import com.dykj.dati.service.user.IHUserService;

import java.util.List;

public class ServiceUtil {
    private static IHUserService hUserService= SpringUtil.getBean(IHUserService.class);
    private static ITJiaojuanService tJiaojuanService= SpringUtil.getBean(ITJiaojuanService.class);
    public static long getUserCountByPhone(String phone){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("phone",phone);
       return hUserService.count(queryWrapper);
    }
    public static boolean hasUser(String uid){
       HUser hUser=hUserService.getById(uid);
        return hUser!=null;
    }
    public static HUser getUserByPhone(String phone){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("phone",phone);
        queryWrapper.last("limit 1");
        return hUserService.getOne(queryWrapper);
    }
    public static boolean isJswb(String uid){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("uid",uid);
        queryWrapper.eq("type",1);
        return tJiaojuanService.count(queryWrapper)!=0;
    }
    public static List<TJiaojuan> getJlByUid(String uid){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("uid",uid);
        queryWrapper.orderByDesc("jj_time");
        return tJiaojuanService.list(queryWrapper);
    }
    public static TJiaojuan getXiangQingByCid(String cid){
        TJiaojuan tJiaojuan=tJiaojuanService.getById(cid);
        HUser hUser=hUserService.getById(tJiaojuan.getUid());
        tJiaojuan.setUserName(hUser.getName());
        tJiaojuan.setPhone(hUser.getPhone());
        tJiaojuan.setTXiangQingList(JSONObject.parseArray(tJiaojuan.getJl(), TXiangQing.class));
        return tJiaojuan;
    }
}
